package lwjgl.engine;

import org.lwjgl.opengl.GL11;


/**
 * A texture to be bound within OpenGL. This object is responsible for
 * keeping track of a given OpenGL texture and for calculating the
 * texturing mapping coordinates of the full image.
 *
 * Since textures need to be powers of 2 the actual texture may be
 * considerably bigged that the source image and hence the texture
 * mapping coordinates need to be adjusted to matchup drawing the
 * sprite against the texture.
 *
 * @author Kevin Glass
 * @author Brian Matzon
 * @author Tim
 *
 * @version 0.5.0
 * @since 0.5.0
 */
public class Texture {

	private int target;
	private int textureID;
	private int height;
	private int width;
	private int texHeight;
	private int texWidth;
	private float widthRatio;
	private float heightRatio;
	
	public Texture(int target, int textureID)
	{
		this.target = target;
		this.textureID = textureID;
	}
	
	public void bind()
	{
		//GL11.glBindTexture(target, textureID);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
	}

	public void setHeight(int height)
	{
		this.height = height;
		setHeight();
	}
	
	public void setHeight()
	{
		if(texHeight != 0)
		{
			heightRatio = ((float)height / texHeight);
		}
	}
	
	public void setTextureHeight(int texHeight)
	{
		this.texHeight = texHeight;
		setHeight();
	}
	
	public float getHeightRatio()
	{
		return heightRatio;
	}
	
	public int getImageHeight()
	{
		return height;
	}
	
	public void setWidth(int width)
	{
		this.width = width;
		setWidth();
	}
	
	public void setWidth()
	{
		if(texWidth != 0)
		{
			widthRatio = ((float)width / texWidth);
		}
	}
	
	public void setTextureWidth(int texWidth)
	{
		this.texWidth = texWidth;
		setWidth();
	}
	
	public float getWidthRatio()
	{
		return widthRatio;
	}
	
	public int getImageWidth()
	{
		return width;
	}
	
}
